package com.jianyun.jyzs.presenter;

import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter;
import com.jianyun.jyzs.bean.NewSignReslut;
import com.jianyun.jyzs.bean.SignNewReslut;
import com.jianyun.jyzs.bean.SignRange;
import com.jianyun.jyzs.bean.SignStateBean;
import com.jianyun.jyzs.bean.WillSignBean;
import com.jianyun.jyzs.model.NewSignModel;
import com.jianyun.jyzs.model.imdoel.INewSignModel;
import com.jianyun.jyzs.view.iview.INewSignView;

import java.util.HashMap;

/**
 * Created by yangshijun on 2018/6/11.
 */

public class NewSignPresenter extends MvpBasePresenter<INewSignView> {
    /**
     * 判断当前位置是否在签到范围
     *
     * @param enterpriseCode
     * @param lat
     * @param lng
     */
    public void judegLoactionRange(String enterpriseCode, String lat, String lng) {
        if (!isViewAttached()) return;
        NewSignModel.getInstance().judegLoactionRange(enterpriseCode, lat, lng, new INewSignModel.OnisLocationRangeListener() {
            @Override
            public void onFailed(String msg) {
                getView().onFailed(msg);
            }

            @Override
            public void onRangeReslut(SignRange signRange) {
                getView().onRangeReslut(signRange);
            }
        });

    }

    /**
     * 获取将要打卡的详细信息
     *
     * @param enterpriseCode
     * @param userId
     */
    public void getNowSignDetail(String enterpriseCode, String userId) {
        if (!isViewAttached()) return;
        NewSignModel.getInstance().getNowSignDetail(enterpriseCode, userId, new INewSignModel.OnGetNowSignDeatileListener() {
            @Override
            public void onSuccess(WillSignBean willSignBean) {
                getView().onNowSignDataile(willSignBean);
            }

            @Override
            public void onFailed(String msg) {
                getView().onFailed(msg);
            }
        });
    }

    /**
     * 获取用户将要打卡后的状态
     *
     * @param enterpriseCode
     * @param userId
     */
    public void getUserSignState(String enterpriseCode, String userId,String signType) {
        if (!isViewAttached()) return;
        NewSignModel.getInstance().getUserSignState(enterpriseCode, userId,signType, new INewSignModel.OnGetNowStateListener() {
            @Override
            public void onSuccess(SignStateBean signStateBean) {
                getView().onUserSignState(signStateBean);
            }

            @Override
            public void onFailed(String msg) {
                getView().onFailed(msg);
            }
        });
    }

    /**
     * 新版打卡
     *
     * @param map
     */
    public void newStartSign(HashMap<String, String> map) {
        if (!isViewAttached()) return;
        NewSignModel.getInstance().newSign(map, new INewSignModel.OnNewSignListener() {
            @Override
            public void onSuccess(SignNewReslut signReslut) {
                getView().onStartSign(signReslut);
            }

            @Override
            public void onFailed(String msg) {
                getView().onSignFailed(msg);
            }
        });
    }
}
